package com.buaa.hyf.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.buaa.hyf.activity.R;
import com.buaa.hyf.util.Globals;

import java.util.Hashtable;
import java.util.List;
import java.util.Map;

/**
 * Created by Jeson on 2016/4/19.
 */
public class StageAdapter extends BaseAdapter {

    private List<Map<String,Object>> values;
    private Context ctx;

    public StageAdapter(List<Map<String,Object>> values,Context ctx){
        this.values = values;
        this.ctx = ctx;
    }
    @Override
    public int getCount() {
        return values.size();
    }

    @Override
    public Object getItem(int position) {
        return values.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if(convertView==null){

            convertView = LayoutInflater.from(ctx).inflate(R.layout.stage_unit,null);
            convertView.setLayoutParams(new AbsListView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, Globals.SCREEN_HEIGHT/9));

        }

        Map<String,Object> map = values.get(position);
        TextView stageNum = (TextView) convertView.findViewById(R.id.stage_num);  //获取小方格的id
        stageNum.setText(map.get("stage_num").toString());   //设置小方格里面的数字
        boolean overFlag = (boolean) map.get("overFlag");    //设置标志位来判断有没有被打通关
        if(overFlag){
            stageNum.setBackgroundColor(Color.WHITE);    //设置打通关的背景色
        }else{
            stageNum.setBackgroundColor(Color.BLACK);
        }



        return convertView;
    }
}
